#!/bin/bash
set -e

# 清空旧构建
rm -rf build/deb
mkdir -p build/deb/DEBIAN

# 安装文件部署
install_dir="build/deb/usr/share/deskmanager"
mkdir -p $install_dir/{src,resources}
cp src/main.py $install_dir/src/
cp -r src/resources/* $install_dir/resources/

# 桌面入口
mkdir -p build/deb/usr/share/applications
cp deskmanager.desktop build/deb/usr/share/applications/

# 启动器
mkdir -p build/deb/usr/bin
cat > build/deb/usr/bin/deskmanager <<EOF
#!/bin/sh
python3 /usr/share/deskmanager/src/main.py "$@"
EOF

# 维护脚本权限设置
chmod 755 build/deb/usr/bin/deskmanager
find build/deb/DEBIAN -name "post*" -o -name "pre*" | xargs chmod 755 

# 构建DEB包
dpkg-deb --build build/deb deskmanager_1.3.2_all.deb

echo "✅ 构建成功: deskmanager_1.3.2_all.deb"